#include "DocGenerate.h"
#include "maddy/parser.h"
#include "css.h"

namespace OCPP
{
	String OpenApiDoc::toString()
	{
		Json::Value rootObj;
		rootObj["openapi"] = "3.1.0";
		Json::Value pathsObj;

		for (auto& m : methodList)
		{
			Json::Value apiObj;
			Json::Value apiGet;
			apiGet["description"] = m.description;
			apiGet["responses"] = Json::objectValue;

			Json::Value apiParams;
			for (auto& p : m.parameterList)
			{
				apiParams["name"] = p.name;
				apiParams["in"] = p.in;
				apiParams["description"] = p.desc;
				//apiParams["required"] = false;
				Json::Value schemaObj;
				schemaObj["type"] = p.type;
				schemaObj["example"] = p.example;
				apiParams["schema"] = schemaObj;
				apiGet["parameters"].append(apiParams);
			}

			apiObj["get"] = apiGet;
			String path = baseUrl.empty() ? m.path : (baseUrl + m.path);
			pathsObj[path] = apiObj;
		}
		

		rootObj["paths"] = pathsObj;

		return rootObj.toStyledString();
	}

	String DocGenerate::toOpenApi(ApiDocMehtodVec apiVec)
	{
		Json::Value rootObj;
		rootObj["openapi"] = "3.1.0";
		Json::Value pathsObj;

		Json::Value apiObj;
		Json::Value apiGet;
		apiGet["description"] = "description";
		apiGet["responses"] = Json::objectValue;
		apiObj["get"] = apiGet;
		String path = "/apiList";
		pathsObj[path] = apiObj;

		rootObj["paths"] = pathsObj;

		return rootObj.toStyledString();
	}

	String DocGenerate::toMarkdown(ApiDocMehtodVec apiVec, String path)
	{
		StringStream mardownStream;
		return mardownStream.str();
	}
}
